<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新零售微店</title>
    <meta name="keywords" content="新零售微店"/>
    <meta name="description" content="新零售微店"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header" th:content="${_csrf.headerName}"/>
    <meta name="viewport" content="width=device-width,viewport-fit=cover">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/swiper.min.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/public.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/index.css}">
    <link th:href="@{/shoppingApi/css/weui.min.css}" rel="stylesheet">
    <link th:href="@{/shoppingApi/css/jquery-weui.min.css}" rel="stylesheet">
    <style>
        .index {
            margin: 0 auto;
            right: 0;
            bottom: 0;
            left: 0;
            width: 100%;
        }

        .index .tabul {
            height: 100%;
            overflow: auto;
            margin-top: 0;
            padding-top: 91px;
        }

        .index .bannerimg {
            margin-top: 0;
        }

        .main_con {
            height: 100%;
        }

        .lingshouzhuanqu {
            display: inline-block;
            height: 45px;
            color: #f70029;
        }

    </style>
</head>
<body>
<div class="index">
    <div class="app-download" th:if="${map!=null&&map.subscribe==null}">
        <a class="source" id="source">关注公众号购物体验更佳</a>
        <img class="close" th:src="@{/shoppingApi/images/app-close-btn.png}" alt="关闭">
    </div>
    <!--<div class="main_con">-->

        <div class="top bgfff">
            <!--<div>-->
            <!--<button onclick="closeWin()">关闭窗口</button>-->
            <!--<button onclick="shareToMessage()">分享给朋友</button>-->
            <!--<button onclick="shartToTimeline()">分享到朋友圈</button>-->

            <!--<button onclick="shareToMessage2()">分享给朋友2</button>-->
            <!--<button onclick="shartToTimeline2()">分享到朋友圈2</button>-->
            <!--</div>-->

            <!--搜索框-->
            <div class="search flex flex-ac">
                <!--<button onclick="closeWin()">分享给好友</button>-->
                <a class="rela" href="/wap/getSysMessage">
                    <img class="w100  message" th:src="@{/shoppingApi/images/mess.png}">
                    <span class="abs num message-count"></span>
                </a>
                <div class="it1">
                    <a th:href="@{/wap/search}" class="flex flex-ac db">
                        <img th:src="@{/shoppingApi/images/search.png}">
                        <input class="it1" type="text" placeholder="请输入关键词">
                    </a>
                </div>
                <a href="javascript:;" class="rela omit" id="shareapp">
                    <img class="w100" th:src="@{/shoppingApi/images/omit.png}">
                </a>
            </div>
            <!--导航栏-->
            <div class="banner pl15 pr15">
                <div class="swiper-container ftc ft14 c323232">
                    <div class="swiper-wrapper">
                        <div class="swiper-slide active"><a href="/wap/productIndex" class="lingshouzhuanqu">零售专区</a>
                        </div>
                        <div class="swiper-slide"><a href="/wap/openDuiHuan?pageNum=1&sign=5" class="duihuan">兑换专区</a>
                        </div>
                        <div class="swiper-slide"><a href="/wap/openTiYan?pageNum=1&sign=3" class="tiyan">体验专区</a></div>
                        <div class="swiper-slide"><a th:href="@{'/wap/openHuoDong?sign=7'}" class="huodong">活动专区</a>
                        <!--<div class="swiper-slide"><a href="javascript:alert('敬请期待')" class="huodong">活动专区</a>-->

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--导航分类1-->
        <div class="tabul">
            <div class="bannerimg">
                <div class="swiper-container ftc ft14 c323232 bold">
                    <div class="swiper-wrapper">
                        <!--<div class="swiper-slide" th:each="panners:${map.pannerLists}">-->
                            <!--<a>-->
                                <!--<img class="w100" th:attr="src=@{${panners.pannerUrl}}" th:width="400px"-->
                                     <!--th:height="160px">-->
                            <!--</a>-->
                        <!--</div>-->
                        <!--<div class="swiper-slide">-->
                            <!--&lt;!&ndash;<a href="/wap/activity?productId=461&guigeId=326"><img class="w100" th:attr="src=@{/shoppingApi/images/banner5.jpg}"></a>&ndash;&gt;-->
                            <!--<a href="/wap/activity?productId=458"><img class="w100" th:attr="src=@{/shoppingApi/images/banner5.jpg}"></a>-->
                        <!--</div>-->
                        <!--<div class="swiper-slide">-->
                            <!--<a><img class="w100" th:attr="src=@{/shoppingApi/images/banner6.jpg}"></a>-->
                        <!--</div>-->
                        <!--<div class="swiper-slide">-->
                            <!--<a  th:href="@{'/wap/activity?productId=491&guigeId=354'}"><img class="w100" th:attr="src=@{/shoppingApi/images/banner7.jpg}"></a>-->
                        <!--</div>-->
                        <!--<div class="swiper-slide">-->
                            <!--<a th:href="@{'/wap/activity?productId=491&guigeId=354'}"><img class="w100" th:attr="src=@{/shoppingApi/images/banner8.jpg}"></a>-->
                        <!--</div>-->
                        <div class="swiper-slide">
                            <a th:href="@{'#'}"><img class="w100" th:attr="src=@{http://xlspic.ycsqd.com/a-1.jpg}"></a>
                        </div>
                        <div class="swiper-slide">
                            <a th:href="@{'#'}"><img class="w100" th:attr="src=@{http://xlspic.ycsqd.com/a-2.jpg}"></a>
                        </div>
                        <div class="swiper-slide">
                            <a th:href="@{'#'}"><img class="w100" th:attr="src=@{http://xlspic.ycsqd.com/b2.jpg}"></a>
                        </div>
                        <div class="swiper-slide">
                            <a th:href="@{'#'}"><img class="w100" th:attr="src=@{http://xlspic.ycsqd.com/b1.jpg}"></a>
                        </div>
                        <!--/wap/getDetails?productId=627&guigeId=505-->
                    </div>
                    <div class="swiper-pagination"></div>
                </div>
            </div>
            <div class="line"></div>
            <!--爆品-->
            <div class="critical_brand rela bgfff">
                <div class="brand1 flex">
                    <a >
                        <!--th:href="${'/wap/getDetails?productId='+map.advList1.productId}"-->
                        <!--<img class="w100 adv-img"  th:attr="src=@{${map.advList1.advUrl}}">-->
                        <img class="w100 adv-img" th:src="@{http://xlspic.ycsqd.com/ycbp1.jpg}">
                    </a>
                    <a >
                        <!--th:href="${'/wap/getDetails?productId='+map.advList2.productId}"-->
                        <!--<img class="w100 adv-img"  th:attr="src=@{${map.advList2.advUrl}}">-->
                        <img class="w100 adv-img" th:src="@{http://xlspic.ycsqd.com/ycbp2.jpg}">
                    </a>
                </div>
                <div class="brand2 flex">
                    <a >
                        <!--th:href="${'/wap/getDetails?productId='+map.advList3.productId}"-->
                        <!--<img class="w100 adv-img"  th:attr="src=@{${map.advList3.advUrl}}">-->
                        <img class="w100 adv-img" th:src="@{http://xlspic.ycsqd.com/ycbp3.jpg}">
                    </a>
                    <a >
                        <!--th:href="${'/wap/getDetails?productId='+map.advList4.productId}"-->
                        <!--<img class="w100 adv-img"  th:attr="src=@{${map.advList4.advUrl}}">-->
                        <img class="w100 adv-img" th:src="@{http://xlspic.ycsqd.com/ycbp4.jpg}">
                    </a>
                </div>
                <!--<img class="abs critical_text" style="left: 0px" th:src="@{/shoppingApi/images/critical.png}">-->
            </div>
            <div class="line"></div>
            <!--热门商品列表-->
            <div class="list c323232">
                <div class="lingshou  page-info">

                    <!--<div class="goods bgfff" th:if="${map!=null}" th:each="indexProduct:${map.indexProductList}">-->
                        <!--<a class='db hot-area product-detail lazyload' onclick="linkTo(this)" href="javascript:"-->
                           <!--th:data-href="${'/wap/getDetails?productId='+indexProduct.productId+'&guigeId='+indexProduct.guigeId}"-->
                           <!--th:style="${'background-image:url(/shoppingApi/images/thumbnail.jpg)'}" th:data-src="${indexProduct.proImg}">-->
                            <!--<input type="hidden" id="productId" name="productId" th:value="${indexProduct.productId}"/>-->
                        <!--</a>-->
                        <!--<div class="title rela">-->
                            <!--<p class="ft16 prodesc bold" th:text="${indexProduct.productName}">传奇天露1箱</p>-->
                            <!--<p class="nft10 ft15 c969696 mt5 mb5">商城价：<span class="ft12">￥</span>-->
                                <!--<span class="" th:text="${indexProduct.proPrice}"></span></p>-->
                            <!--<input type="hidden" class="finace-cash" th:value="${indexProduct.yzDianzhu}"/>-->

                            <!--<p th:if="${map.userCommission>map.newUserCommission}" class="minhy-price">-->
                                <!--<span class="ft16 bold">自用价：</span><span class="ft12 cf70029 bold">￥</span><span class="ft16 cf70029 bold" th:text="${#numbers.formatDecimal(indexProduct.minyhPrice,1,2)}">0 </span>-->
                            <!--</p>-->
                            <!--<p th:if="${map.userCommission<=map.newUserCommission&&map.userNo!=null}" class="minhy-price">-->
                                <!--<span class="ft16 bold">可用代金券：</span><span class="ft12 cf70029 bold">￥</span><span class="ft16 cf70029 bold" th:text="${#numbers.formatDecimal(indexProduct.yzDianzhu,1,2)}">0 </span>-->
                            <!--</p>-->

                            <!--<a onclick="linkTo(this)" href="javascript:" th:data-href="${'/wap/getDetails?productId='+indexProduct.productId+'&guigeId='+indexProduct.guigeId}" class="share abs ftc" style="padding:6px 0;right:90px;background-color:#ff9900;">-->
                                <!--<p class="ft12">自用省</p>-->
                            <!--</a>-->
                            <!--<div class="share abs ftc" style="padding:6px 0;" onclick="shareAndEarn(this)"-->
                                 <!--th:data-id="${indexProduct.productId}" th:data-desc="${indexProduct.productName}"-->
                                 <!--th:data-img="${indexProduct.proImg}" th:data-value="${#numbers.formatDecimal(indexProduct.fenXiangZhuan,1,2)}">-->
                                <!--<p class="ft12">分享赚</p>-->
                                <!--<input type="hidden" class="share-money" name="fenXianZhuan"/>-->
                                <!--&lt;!&ndash;<p class="nft10">赚￥<label class="share-money" th:text="${#numbers.formatDecimal(indexProduct.fenXiangZhuan,1,2)}">0</label></p>&ndash;&gt;-->
                            <!--</div>-->
                        <!--</div>-->
                        <!--<div class="line"></div>-->
                    <!--</div>-->


            </div>
            <div id="load-state">
                已加载完成！
            </div>
            <!--滚动加载-->
            <!--<div class="weui-infinite-scroll">-->
            <!--<div class="infinite-preloader"></div>-->
            <!--正在加载... -->
            <!--</div>-->
        </div>

        </div>
        <!--导航分类2  -->
        <span class="back-top"></span>
        <div class="fixedBox50">
            <ul class="fixed-bottom bottom flex flex-pc ftc bgfff nft10 c323232">
                <li class="it1 active">
                    <a class="db">
                        <span class="img"></span>
                        <span>首页</span>
                    </a>
                </li>
                <li class="it1">
                    <a th:href="@{/wap/selectProductYJAndRjClassfy}" class="db">
                        <span class="img"></span>
                        <span>分类</span>
                    </a>
                </li>
                <li class="it1">
                    <a th:href="@{/wap/getCartList}" class="db">
                        <span class="img"></span>
                        <span>购物车</span>
                    </a>
                </li>
                <li class="it1">
                    <a th:href="@{/wap/openUserCenter}" class="db">
                        <span class="img"></span>
                        <span>我的</span>
                    </a>
                </li>
            </ul>
        </div>
    <!--</div>-->
</div>
<!--分享弹窗-->
<div id="sharePopup" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal share-layer">
        <!--未登录-->
        <!--th:if="${map.userNo==null || map.userCommission==0}"-->
        <!--th:if="${map.userNo==null || map.userCommission==0}""-->

        <p class="ft14 c323232" style="padding: 15px 35px 10px 35px;" ><span class="share-info" >1.注册获得代金券,为你购物省钱</span></p>
        <p class="ft14 c323232" style="padding: 0 35px;" ><span class="share-info">2.分享给朋友，双方都获得代金券</span></p>
        <p class="ft17 cff0000 mb10 mt10 text-center" >赚<label class="share-fenXiangZhuan"></label></p>
        <p class="ft14 c323232" style="padding: 0 35px;" >只要你的好友通过你的链接购买此商品，你就能赚到至少<span class="cf70029  share-fenXiangZhuan"></span>元利润</p>
        <p class="flex mt20 mb20 flex-ac pl15 pr15">
            <span class="ml20 mr20 it1 lineh1"></span>
            <span class="ft14 c323232">分享到</span>
            <span class="ml20 mr20 it1 lineh1"></span>
        </p>
        <ul class="overflow ft14 c323232 ftc">
            <li id="shareMessage">
                <img class="wxhaoyou" th:src="@{/shoppingApi/images/share1.png}">
                <p class="mt10 ">微信好友</p>
            </li>
            <li id="shareTimeline">
                <img th:src="@{/shoppingApi/images/share2.png}">
                <p class="mt10">朋友圈</p>
            </li>
            <li id="shareImg">
                <img th:src="@{/shoppingApi/images/share4.png}">
                <p class="mt10">生成分享图</p>
            </li>
        </ul>
        <img class="close close-popup" th:src="@{/shoppingApi/images/close3.png}">
    </div>
</div>
<!--生成二维码-->
<!--<div id="imageLayer" class="weui-gallery" style="background:rgba(0,0,0,0.8);">-->
<div id="imageLayer" class="weui-gallery">
    <!--<img style="position:absolute;top:8%;left:15%;width:70%;" alt="">-->
    <div id="createImg" style="position:absolute;top:0;left:0;width:100%;height:100%;"></div>
    <!--<div class="weui-gallery__opr" id="saveImage" onclick="captureWebview()">长按图片保存</div>-->
</div>

<!--<input type="hidden" class="user-no-id" th:if="${map.userNo!=null}" th:value="${map.userNo.id}">-->
<!--<input type="hidden" class="user-no-id" th:if="${map.userNo==null}" value="">-->
<!--<input type="hidden" class="finace-name" th:value="${map.config.finacename3}">-->
<!--<input type="hidden" class="finace-count" th:value="${map.config.giftDiscount}">-->
<!--<input type="hidden" class="new-user-commission" th:value="${map.newUserCommission}">-->
<!--<input type="hidden" class="user-commission" th:value="${map.userCommission}">-->


<style>.weui-toast--text{top:80%;}</style>
<div id="mini-popup" class="weui-popup__container popup-bottom">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal share-layer">
        <p class="flex mt20 mb20 flex-ac pl15 pr15">
            <span class="ml20 mr20 it1 lineh1"></span>
            <span class="ft14 c323232">分享到</span>
            <span class="ml20 mr20 it1 lineh1"></span>
        </p>
        <ul class="overflow ft14 c323232 ftc">
            <li id="miniShareMessage">
                <img class="wxhaoyou" th:src="@{/shoppingApi/images/share1.png}">
                <p class="mt10 ">微信好友</p>
            </li>
            <li id="miniShareTimeline">
                <img th:src="@{/shoppingApi/images/share2.png}">
                <p class="mt10">朋友圈</p>
            </li>
        </ul>
        <img class="close close-popup" th:src="@{/shoppingApi/images/close3.png}">
    </div>
</div>
</body>
<script th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
<!--<script th:src="@{/shoppingApi/js/common.js}"></script>-->
<script th:src="@{/shoppingApi/js/swiper.min.js}"></script>
<!--<script th:src="@{/shoppingApi/js/jweixin-1.0.0.js}"></script>-->
<!--<script th:src="@{/shoppingApi/js/jweixin-1.4.0.js}"></script>-->
<script th:src="@{/shoppingApi/js/jquery-weui.min.js}"></script>
<!--<script type="text/javascript" th:src="@{/shoppingApi/js/H5Plus/common.js}"></script>-->
<script type="text/javascript" th:src="@{/shoppingApi/js/lazyload.min.js}"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/common.js}"></script>
<script type="text/javascript" th:src="@{/shoppingApi/js/plusShare.js}"></script>
<script th:src="@{/shoppingApi/js/mininav.js}"></script>
<script>
    //滚动加载
    var page=1;
    var loading = false;  //状态标记
    $(function () {
        loadList();
    })
    $(document.body).infinite().on("infinite", function() {
        console.log('加载前：'+loading)
        if(loading) return;
        loadList()
    });

    function loadList() {
        // $.showLoading("正在加载...");
        loading = true;
        $.ajax({
            url: '/wap/getIndexData?page=' + page,
            success: function (res) {
                if (page <= res.pageCount) {
                    $.hideLoading();
                    getDuiHuanData(res);
                    loading = false;
                    page++;
                }else{


                    //
                    // setTimeout(function () {
                    //     // $.hideLoading();
                    //     $.showLoading("已加载全部...");
                    //     loading = true;
                    //     // page++;
                    //     // console.log(res.indexProductList);
                    // }, 0);
                }
                // console.log(res);

            }
        })
    }


    var userNoId = $('#userNoId').val();

    // var isLogin =
    function getDuiHuanData(duiHuanData) {
        var html = '';
        var lists = duiHuanData.indexProductList;
        $.each(lists, function (i, item) {
            html += `<div class="goods bgfff">
                        <a class='db hot-area product-detail' onclick="linkTo(this)" href="javascript:"
                           data-href="/wap/getDetails?productId=${item.productId}&guigeId=${item.guigeId}"
                           style="background-image:url(http://xlspic.ycsqd.com${item.proImg})">
                            <input type="hidden" id="${item.productId}" name="productId" value="${item.productId}"/>
                        </a>
                        <div class="title rela">
                            <p class="ft16 prodesc bold">${item.productName}</p>
                            <p class="nft10 ft15 c969696 mt5 mb5">商城价：<span class="ft12">￥</span>
                                <span class="">${item.proPrice.toFixed(2)}</span></p>
                            <input type="hidden" class="finace-cash" value="${item.yzDianzhu}"/>

                            <p class="minhy-price" style="display:${item.minyhPrice == 0.00 || item.productId == 438 ? 'none' : 'block'};">
                                <span class="ft16 bold">自用价：</span><span class="ft12 cf70029 bold">￥</span><span class="ft16 cf70029 bold" >${item.minyhPrice.toFixed(2)} </span>
                            </p>
                            <p class="minhy-price"   style="display:${item.yzDianzhu == 0 ? 'none' : 'block'};">
                                <span class="ft16 bold">可用代金券：</span><span class="ft12 cf70029 bold">￥</span><span class="ft16 cf70029 bold" >${item.yzDianzhu.toFixed(2)}</span>
                            </p>

                            <a onclick="linkTo(this)" href="javascript:" data-href="/wap/getDetails?productId=${item.productId}&guigeId=${item.guigeId}" class="share abs ftc" style="padding:6px 0;right:90px;background-color:#ff9900;">
                                <p class="ft12">自用省</p>
                            </a>
                            <div class="share abs ftc" style="padding:6px 0;" onclick="shareAndEarn(this)"
                                 data-id="${item.productId}" data-desc="${item.productName}"
                                 data-img="${item.proImg}" data-value="${item.fenXiangZhuan.toFixed(2)}">
                                <p class="ft12">分享赚</p>
                                <input type="hidden" class="share-money" name="fenXianZhuan"/>
                            </div>
                        </div>
                        <div class="line"></div>
                    </div>`

        })
        $('.page-info').append(html);
    }
</script>
<script>

    $("#source").on('click', function () {
        $.modal({
            title: "",
            text: "<img src='/gzhewm.jpg' width='100%' />",
            buttons: [
                {
                    text: "关闭", className: "default", onClick: function () {
                        console.log(3)
                    }
                },
            ]
        });
    });


    // 图片延迟加载
    $(".lazyload").lazyload();

    /*回到顶部*/
    $(".back-top").on('click', function () {
        $(".tabul").animate({
            scrollTop: 0
        }, 500)
    })

    // 轮播图
    var mySwiperimg = new Swiper('.bannerimg .swiper-container', {
        slidesPerView: 1,
        observer: true,
        observeParents: true,
        autoplay: true,
        pagination: {
            el: '.swiper-pagination',
        },
    })
    //首页消息显示条数
    $(function () {
        $.ajax({
            url: '/wap/getAllMessages',
            success: function (result) {
                // console.log(result);
                $('.message-count').html(result.allMessageSize);
                if (result.allMessageSize == 0) {
                    $('.message-count').hide();
                }
            }
        })
    })

    // 分享赚
    var proId = '';
    var proTitle = '';
    var proImg = '';
    // var userNoId = '';
    var qrImgUrl = '';
    $.toast.prototype.defaults.duration = 1000;
    $(function () {
        if (isApp()) {
            $('#saveImage').text('保存到手机相册');
        } else {
            $('.app-download').show();
            $('.app-download .close').click(function () {
                $('.app-download').hide();
            });
        }

        $('#shareapp').click(function (e) {
            $('#mini-popup').popup();
        });
        // 分享朋友按钮
        $('#shareMessage').on('click', function () {
            if (!isLogin(userNoId, true, '登陆后才能分享')) return;
            if (isApp()) {
                // downloadEl.style.display = "none";//隐藏下载banner
                //分享内容，开发者可自定义
                var message = {
                    title: proTitle, //应用名字
                    content: "社区零售商店，优惠的价格购买满意的商品",
                    href: location.host+ "/wap/getDetails?productId=" + proId + "&userNoId=" + userNoId, //分享出去后，点击跳转地址
                    thumbs: [proImg] //分享缩略图
                }
                //调起分享
                shareMessage(message, function (res) {
                    //分享回调函数
                    if (res) {
                        plus.nativeUI.toast("分享成功");
                    } else {
                        plus.nativeUI.toast("分享失败");
                    }
                    $.closePopup();
                })

            } else {
                // $.toast('请生成分享图', 'forbidden');
                qrImg();
            }
        });
        // 分享朋友圈按钮
        $('#shareTimeline').on('click', function () {
            if (!isLogin(userNoId, true, '登陆后才能分享')) return;
            if (isApp()) {
                // downloadEl.style.display = "none";//隐藏下载banner
                //分享内容，开发者可自定义
                var message = {
                    title: proTitle, //应用名字
                    content: proTitle,
                    href: location.host + "/wap/getDetails?productId=" + proId + "&userNoId=" + userNoId, //分享出去后，点击跳转地址
                    thumbs: [proImg] //分享缩略图
                }
                //调起分享
                shareTimeline(message, function (res) {
                    //分享回调函数
                    if (res) {
                        plus.nativeUI.toast("分享成功");
                    } else {
                        plus.nativeUI.toast("分享失败");
                    }
                    $.closePopup();
                })

            } else {
                // $.toast('请生成分享图', 'forbidden');
                qrImg();
            }
        });
        // 生成二位码按钮
        $('#shareImg').on('click', function () {
            if (!isLogin(userNoId, true, '登陆后才能生成分享图')) return;
            qrImg();
        });

        // 点击遮罩关闭浮层
        $('#imageLayer').on('click', function (e) {
            // var target = $(e.target);
            // if (target.is('#imageLayer')) {
            //     target.hide();
            // }
            $(this).hide();
        });

        // 双击返回按钮退出应用
        if (isApp()) {
            var first = null;
            mui.back = function () {
                //首次按键，提示‘再按一次退出应用’
                if (!first) {
                    first = new Date().getTime();
                    mui.toast('再按一次退出应用');
                    setTimeout(function () {
                        first = null;
                    }, 1000);
                } else {
                    if (new Date().getTime() - first < 1000) {
                        plus.runtime.quit();
                    }
                }

            };
        }
    });

    // 打开分享操作面板
    function shareAndEarn(obj) {
        // userNoId = $('.user-no-id').val();

        proId = $(obj).data('id');
        proTitle = $(obj).data('desc');
        proImg = location.host + $(obj).data('img');
        // $('.share-fenXiangZhuan').html($(obj).find('label').text());
        $('.share-fenXiangZhuan').text($(obj).data('value'));

        $('#sharePopup').popup();
    }

    // 详情页跳转
    function linkTo(obj) {
        location.href = $(obj).data('href') + '&usernoid=' + ($('.user-no-id').val() || '');
    }

    // 生成分享图片
    function qrImg() {
        $.showLoading('图片生成中');
        $.closePopup();
        $.ajax({
            type: 'get',
            url: '/wap/getEnCode?productId=' + proId,
            success: function (res) {
                if (res.loginInfo == 'unlogin') {
                    $.toast('请去个人中心登录！', 'cancel');
                    return;
                }

                if (res.ewmURL) {
                    console.log(res.ewmURL)
                    console.log(typeof (res.ewmURL));

                    $.hideLoading();
                    // 图片生成成功，打开浮层，关闭分享弹窗
                    imageLayer(res.ewmURL);
                } else {
                    setTimeout(function () {
                        $.hideLoading();
                        $.toast('图片生成失败', 'cancel');
                    }, 6000);
                }
            },
            error: function (err) {
                $.toast('图片生成失败', 'cancel');
                $.hideLoading();
            }
        });
    }

    // 图片浮层
    function imageLayer(img) {
        var layout = $('#imageLayer');
        qrImgUrl = location.host + img;
        // layout.find('img').attr('src', img);
        $('#createImg').css({
            background: 'url('+img+') center no-repeat rgba(0,0,0,0.8)',
            backgroundSize: 'contain'
        })
        layout.show();
        $.toast('请截图保存', 'text');
    }

    //根据登录情况、等级显示商城价格
    // showProPriceByLogin();
    // function showProPriceByLogin() {
    //     var userNoId = $('.user-no-id').val();
    //     var newuserCommission = $('.new-user-commission').val();
    //     var userCommission = $('.user-commission').val();
    //     var finaceCash =$.trim(parseFloat($('.finace-cash').val()).toFixed(2));
    //
    //     if (userNoId==0) {
    //         $('.minhy-price').hide();
    //         $('.share-money').html($('.finace-count').val());
    //         $('.goods .rela').find('p:eq(1)').css({color: '#323232', fontSize: '15px'});
    //         $('.goods .rela').find('p:eq(1)').find('span').css({color: '#f70029', fontSize: '15px'});
    //     } else {
    //         if (userCommission <=newuserCommission) {
    //              $('.minhy-price')
    //             $('.minhy-price').html('<span class="ft15 bold">可用代金券：</span><span class="ft14 cf70029">￥</span><span class="cf70029 ft15 bold">' + finaceCash+'</span>');
    //             $('.share-money').html($('.finace-count').val());
    //         }
    //     }
    // }

    // app诊断
    function isApp () {
        return navigator.userAgent.indexOf("Html5Plus") > -1;
    }

    // 扩展API加载完毕后调用onPlusReady回调函数
    document.addEventListener( "plusready", onPlusReady, false );
    var r = null;
    // 扩展API加载完毕，现在可以正常调用扩展API
    function onPlusReady() {}
    // 保存图片到相册中
    function savePicture() {
        // plus.gallery.save( "_doc/a.jpg", function () {
        //     alert( "保存图片到相册成功" );
        // } );
        // if (isApp()) {
        //     plus.gallery.save(qrImgUrl, function () {
        //         plus.nativeUI.toast("保存成功");
        //     }, function () {
        //         plus.nativeUI.toast("保存失败");
        //     });
        // }
        $('#imageLayer').hide();
    }
    // 保存图片后关闭浮层
    // $('#saveImage').on('click', function (e) {
    //     if (isApp()) {
    //         plus.gallery.save(qrImgUrl, function () {
    //             plus.nativeUI.toast("保存成功");
    //         }, function () {
    //             plus.nativeUI.toast("保存失败");
    //         });
    //     }
    //     $('#imageLayer').hide();
    // });


    // var ws=null;
    // // H5 plus事件处理
    // function plusReady(){
    //     ws=plus.webview.currentWebview();
    // }
    // if(window.plus){
    //     plusReady();
    // }else{
    //     document.addEventListener('plusready', plusReady, false);
    // }
    // // 截屏绘制
    // var bitmap=null;
    // function captureWebview() {
    //     if (isApp()) {
    //         bitmap = new plus.nativeObj.Bitmap('test');
    //         // 将webview内容绘制到Bitmap对象中
    //         ws.draw(bitmap, function () {
    //             plus.nativeUI.toast('截图保存成功');
    //         }, function (e) {
    //             plus.nativeUI.toast('截图保存失败');
    //         }, {
    //             check: true,	// 设置为检测白屏
    //             clip: {top: '8%', left: '15%', height: '82%', width: '70%'}	// 设置截屏区域
    //         });
    //     }
    //     $('#imageLayer').hide();
    // }




</script>
</html>
